package com.lian.community.util;

import com.lian.community.constant.RedisKeyType;
import com.lian.community.exception.ParamIllegalException;

/**
 * 为了避免有key名字重复，故设置一个生成keyName的util
 */
public class RedisKeyUtil {


    private static final String LOGIN_PERSISTENCE = "TOKEN";
    private static final String SPILT = ":";
    private static final String BIZ_LIKE = "LIKE";
    private static final String BIZ_DISLIKE = "DISLIKE";
    private static final String EVENT_QUEUE = "EVENT_QUEUE";
    // 用户的粉丝列表的名称
    private static final String BIZ_FOLLOWER = "FOLLOWER";
    // 用户关注的类型的列表名称
    private static final String BIZ_FOLLOWEE = "FOLLOWEE";




    public static String getEventKey(){
        return getKey(EVENT_QUEUE);
    }

    public static String get(int entityId, int entityType, int keyType){
         switch (keyType){
             case RedisKeyType.LIKE:
                 return getKey(BIZ_LIKE, entityId, entityType);
             case RedisKeyType.DISLIKE:
                 return getKey(BIZ_DISLIKE, entityId, entityType);
             case RedisKeyType.FOLLOWER:
                 return getKey(BIZ_FOLLOWER, entityId, entityType);
             case RedisKeyType.FOLLOWEE:
                 return getKey(BIZ_FOLLOWEE, entityId, entityType);
             case RedisKeyType.LOGIN_PERSISTENCE:
                 return getKey(LOGIN_PERSISTENCE, entityId, entityType);
                 default:
                 throw new ParamIllegalException("没有这种redisKey Type！");
         }
    }

    private static String getKey(String keyTypeName){
        StringBuilder builder = new StringBuilder();
        return builder
                .append(keyTypeName)
                .toString();

    }

    private static String getKey(String keyTypeName,int entityId, int entityType){
        StringBuilder builder = new StringBuilder();
        return builder
                .append(keyTypeName)
                .append(SPILT)
                .append(entityType)
                .append(SPILT)
                .append(entityId).toString();
    }


}
